﻿#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using JigLibX.Collision;
using JigLibX.Physics;
using JigLibX.Geometry;
using JigLibX.Math;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace sqengine.PhysicObjects
{

    public class StaticObject : BasicObject
    {
        Game _game;
        bool _movable;
        CollisionSkin _terrain_obj;

        public StaticObject(Game game, string ObjName, Model _model, Matrix orientation, float objscale, Vector3 position, bool movable)
            : base(game, _model,string.Empty)
        {
            body = new Body();
            _game = game;
            Name = ObjName;
            _movable = movable;

            if (((sqengine)_game).heightmapObj != null)
                _terrain_obj = ((sqengine)_game).heightmapObj.PhysicsSkin;
            else
                _terrain_obj = ((sqengine)_game).planeObj.PhysicsSkin;

            collision = new CollisionSkin(body);

            collision.AddPrimitive(BuildPhysicsBoxFromModel(_model, orientation), new MaterialProperties(0.8f, 0.8f, 0.7f));
            body.CollisionSkin = this.collision;
            body.CollisionSkin.callbackFn += new CollisionCallbackFn(CollisionSkin_callbackFn);
            body.MoveTo(position, Matrix.Identity);
            body.EnableBody();


        }

        bool CollisionSkin_callbackFn(CollisionSkin skin0, CollisionSkin skin1)
        {
             // skin0 will be MyObject's collision skin
            // skin1 will be the collision skin of the object that has collided with my object

            if (skin1 == _terrain_obj)
            {
                if (!_movable)
                    body.Immovable = true;
            }
            return true;
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            
        }

        public override void ApplyEffects(BasicEffect effect)
        {
            //effect.DiffuseColor = color;
        }

    }


}
